/**
 * Created by Administrator on 2018/3/21.
 */
var taskInfo = new Vue({
    el: '#taskInfo',
    data:{
        content: '',
        date1: '',
        date2: '',
        // name: [],
        region:'',
        regionItems:[],
        fileList2:[],
        taskForm: {
            content: '',
            date1: '',
            date2: '',
            //name: [],
            region:'',
            regionItems:[],
            fileList2: [],
        },
        isContent:function () {
            if(!taskInfo.taskForm.content){
                $("#checkConten").show();
            }else {
                $("#checkConten").hide();
            }
        }
    },
    methods: {
        taskSave: function (event) {
            this.showTask = !this.showTask;
            this.taskForm.describe = event.target.innerText;
        },
        handleNodeClick: function (data, event) {
            console.log(data);
            if (event.data.noChildren) {
                this.taskForm.name = data.label;
            }
        },
        handleRemove: function (file, fileList) {
            console.log(file, fileList);
        },
        handlePreview: function (file) {
            console.log(file);
        },
        uploadFile:function (param) {
            debugger
            var fileObj = param.file;
            //接收上传文件的后台地址
            var fileUrl = "../../pms/task/uploadFile"
            var form = new FormData;
            //文件对象
            form.append("file",fileObj);
            //其他参数
            form.append("xxx","");
            //XMLHttpRequest对象
            var xhr = new XMLHttpRequest();
            xhr.open("post",fileUrl,true);
            xhr.upload.addEventListener("progress",this.progressFunction,false);//监听
            xhr.onload = function () {
                this.$message({
                    showClose: true,
                    message: '文件上传成功！',
                    type: 'success'
                });
            }
        },
        progressFunction: function () {
            if (vm.i == 0) { //控制上传中状态只执行一次上传
                vm.showStatus();
                vm.showProgress = true;
                vm.i = 1;
            }
        },
        getRegionList:function(){
            var redionList = [{regionName:'不重复',regionId:"0"},{regionName:'工作日',regionId:"1"},{regionName:'工作日（含周末）',regionId:"2"},{regionName:'每周',regionId:"3"},{regionName:'每月',regionId:"4"}];
            this.regionItems=redionList;

        },
        isContent:function () {
            if(!taskInfo.taskForm.content){
                $("#checkConten").show();
            }else {
                $("#checkConten").hide();
            }
        },
        isDate1:function () {
            if(!taskInfo.taskForm.content){
                $("#checkDate1").show();
            }else {
                $("#checkDate1").hide();
            }
        },
        isDate2:function () {
            if(!taskInfo.taskForm.content){
                $("#checkDate2").show();
            }else {
                $("#checkDate2").hide();
            }
        },
        isRegion:function () {
            if(!taskInfo.taskForm.content){
                $("#checkRegion").show();
            }else {
                $("#checkRegion").hide();
            }
        },
        onSubmit: function () {
            debugger
            var managetest = this.$message;
            var taskType = sessionStorage.getItem("taskType");
            //验证
            var content = "";
            if(!taskInfo.taskForm.content){
                $("#checkConten").show();
            }else {
                content =taskInfo.taskForm.content;
                $("#checkConten").hide();
            }

            var date1 = "";
            if(!taskInfo.taskForm.date1){
                $("#checkDate1").show();
            }else {
                date1 =taskInfo.taskForm.date1;
                $("#checkDate1").hide();
            }
            var date2 = "";
            if(!taskInfo.taskForm.date2){
                $("#checkDate2").show();
            }else {
                date2 =taskInfo.taskForm.date2;
                $("#checkDate2").hide();
            }
            var regionId = "";
            if(!taskInfo.taskForm.region){
                $("#checkRegion").show();
            }else {
                regionId =taskInfo.taskForm.region;
                $("#checkRegion").hide();
            }
            if("" != content && "" != date1 && "" != date2 && "" != regionId){
                $.ajax({
                    type:"POST",
                    url:'../../pms/task/addTask',
                    async:false,
                    data:{
                        "content":content,
                        "date1":date1,
                        "date2":date2,
                        "regionId":regionId,
                        "taskType":taskType,
                        "taskIntegral":"",
                        "responsibilityUserId":"",
                        "relationshipParentTaskId":""
                    },
                    success: function(msg){
                        debugger
                        managetest({
                            showClose: true,
                            message: '任务提交成功！',
                            type: 'success'
                        });
                        setTimeout(function () {
                            window.parent.document.getElementById("mainframe").setAttribute('src', 'detail.html')
                        }, 2000)
                    },
                    error : function() {
                        managetest({
                            showClose: true,
                            message: '提交失败，稍后重试！',
                            type: 'error'
                        });
                    }
                });
            }
        },
        onReset: function () {
            window.parent.document.getElementById("mainframe").setAttribute('src', 'detail.html')
        },
    },
    created:function(){
        this.getRegionList();
        $("input[name='file']").hide();
    },
})